package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.BrandDTO;
import cn.tedu.csmall.product.pojo.entity.Brand;
import cn.tedu.csmall.product.pojo.vo.BrandListItemVO;
import cn.tedu.csmall.product.pojo.vo.BrandStandardListItemVO;
import cn.tedu.csmall.product.pojo.vo.BrandStandardVO;
import cn.tedu.csmall.product.service.BrandService;
import cn.tedu.csmall.product.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 程旭东
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @RequestMapping("/add-new")
    public JsonResult addNew(@RequestBody BrandDTO brandDTO){
        brandService.addNew(brandDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}")
    public JsonResult getById(@PathVariable("id") Long id){
        BrandStandardVO brandStandardVO = brandService.getById(id);
        return JsonResult.ok(brandStandardVO);
    }

    @GetMapping("/list")
    public JsonResult list(){
        List<BrandListItemVO> list = brandService.list();
        return JsonResult.ok(list);
    }

    @GetMapping("/deleteById")
    public JsonResult deleteById(Long id){
        brandService.deleteById(id);
        return JsonResult.ok();
    }
}
